<template>
	<view class="mains">
	<view class="headers">
		<view class="jieshao">
			<div class="box1">
					<image :src="wx_nick_name"></image>
			</div>
			<div class="box2">
				<div>
					<h3>{{wx_nick_name}}</h3>
				</div>

				<div>
					<p>微信号：{{id}}</p>
				</div>
			</div>


		</view>
	</view>
	
	<view class="box3">
		<u-form :model="form" ref="uForm" >
			<div class="name">
				<u-form-item label="名称"  label-width="4rem" border-bottom="false">
					<u-input   v-model="form.name" placeholder="请输入名称" /></u-form-item>
			</div>
			<div class="name">
				<u-form-item label="手机号:" label-width="5rem" border-bottom="false">
					<u-input   v-model="form.phone" placeholder="请输入手机号" />
				</u-form-item>
			</div>
			<div class="name" >
				<u-form-item label="证件" :label-position="auto-upload"	 :error-type="errorType" label-width="500upx">
					<u-upload   style="text-indent: 0;" ref="uUpload" :action="action" :file-list="fileList" :auto-upload="true" :max-count="1" :header="header"
					 :name="name" @on-uploaded="onUploaded" :before-upload="beforeUpload" size-type="compressed"></u-upload>
				</u-form-item>
				<!-- <div>
					证件：
				</div>
				<div >
					<u-upload ref="uUpload"  :show-tips="false" @click="changchuanimag()"/>
				</div> -->
					
			</div>

		</u-form>
		
	</view>
	<div class="baocun" @click="fasong()">
		保存
	</div>
	<u-toast ref="uToast" />

</view>
</template>

<script>
	export default {
		data(){
			return {
				header: {
					"token": this.$tok
				},
				action:this.action = this.$url + "/index.php/api/v1.Tool/uploadFlie",
				idcard:"",
				wx_nick_name:"",
				wx_total:"",
				id:"",
				agent_id:"",
				fileList:true,
				wanshanimg:"",
				name:"img",
				form: {
					name: '',
					phone:"",
					idcard:""
							},
				lists:"",
				filesArr:"",
			}
		},
		onLoad() {
			this.getyonghuid()
			this.uUpload = this.$refs.uUpload
			this.action = this.$url + "/index.php/api/v1.Tool/uploadFlie"
		},
		methods:{
			loginsuccess(){
				this.$refs.uToast.show({
									title: '登录成功',
									type: 'success',
									icon:"default",
									url: '/pages/shop/addshop'
								})
								
			},
			loginfail(x){
					this.$refs.uToast.show({
									title: x,
									type: 'warning',
								})
								
			},
			beforeUpload(index, list) {
				if (index % 2 == 0) return true;
				else return false;
			},
			onUploaded(lists) {
				// 正在上传中和回调的数据
				this.filesArr = lists;
				this.wanshanimg=this.$url + lists[0].response.url
				console.log(this.wanshanimg);
				// console.log(this.$url + lists[0].response.url)
				// console.log(this.filesArr.url);
			
				// this.shop_urls = this.$url + lists[0].response.url
				// console.log(this.shop_urls);
				// console.log(this.filesArr[0].url)
				// console.log(this.filesArr)
			},
			getyonghuid(){
				var token=wx.getStorageSync("token")
				var agent_id=wx.getStorageSync("agent_id")
				var timeid=wx.getStorageSync("timeid")
				var goodsit=wx.getStorageSync("goodsit")
				this.agent_id=agent_id
				this.token=token
				this.wx_total=timeid.wx_total
				this.wx_nick_name=timeid.wx_nick_name
				this.id=goodsit
				// console.log("获取了自己的token"+token+"业务员id"+agent_id)
				// console.log("获取了客户信息"+timeid.wx_nick_name+timeid.wx_total)
			},
			// changchuanimag(){
				// 手写的上传图片
			// 	var that=this
			// 	wx.chooseImage({
			// 	  success (res) {
			// 	    const tempFilePaths = res.tempFilePaths
			// 		that.idcard=res.tempFilePaths[0]
			// 		wx.uploadFile({
			// 		              url: that.$url+'/index.php/api/v1.Tool/uploadFlie', //仅为示例，非真实的接口地址
			// 		              filePath: tempFilePaths[0],
			// 		              name: 'img',
			// 		            header:{
			// 		              "content-type":'application/form-data',
			// 		              'token':wx.getStorageSync("token")
			// 		            },
			// 		              success (res){
			// 						  var imgRes=JSON.parse(res.data)
			// 						console.log(imgRes)
			// 		              }
			// 		            })
			// 	  //   wx.uploadFile({
			// 	  //     url: 'http://pddht.com/index.php/api/v1.Tool/uploadFlie', //仅为示例，非真实的接口地址
			// 	  //     filePath: res.tempFilePaths[0],
			// 	  //     name: 'img',
			// 		 //  header: {
			// 			// 'token': wx.getStorageSync("token"),  //如果需要token的话要传
			// 			// },
			// 	  //     success (res){
			// 	  //       const data = res.data
			// 			// console.log("本地图片列表"+that.idcard)
			// 			// console.log("微信上传图片"+res)
			// 	  //     }
			// 	  //   })
			// 	  }
			// 	})
			// },
			fasong(){
				var that=this
				let arr=[]
				console.log("要发送的数据")
				console.log(that.form.name)
				console.log(that.form.phone)
				console.log(that.agent_id)
				console.log(that.idcard)
				console.log(that.id)
				wx.request({
				         url: that.$url+'/api/v1.Customer/addCustomer', //仅为示例，并非真实的接口地址
				         method:'post',
				         data: {
						   true_name:that.form.name,
						   tel:that.form.phone,
						   agent_id:that.agent_id,
						   idcard_url:that.wanshanimg,
						   wx_user_id:that.id
				         },
				          header: {
				              token:that.token // 默认值
				            },
				          success(res){
				            console.log("发送成功")
							console.log("res.data.msg")
							console.log(res.data.msg)
							if(res.data.msg=="成功"){
								console.log("提示成功")
							}
							else{
								console.log("提示失败")
								that.loginfail(res.data.msg)
							}
							
				      // console.log(that.lists)
				      // arr=that.lists
					  // var x=JSON.parse(JSON.stringify(res))
						// var x= res.toString()
						console.log("data的数据变回了")
				          },
				          fail(ref){
				           console.log("发送失败")
						   console.log(ref)
				          }
				        })
			}
		}
	}
</script>

<style scoped="scoped" lang="scss">
	.boxxian{
		height:10upx ;
		background-color: #f4f4f4;
	}
	.idimgsbox{
		height: 300upx;
		width: 300upx;
		margin:0 50rpx;
	}
	.baocun{
		box-sizing: border-box;
		background-color: $red;
		color: $f;
		align-content: flex-end;
		margin-left: 46upx;
		margin-right: 46upx;
		// padding: 0 46upx;
		// margin-left: 46upx;
		// padding-right: 46upx;
		margin-bottom: 46upx;
		font-size: 32upx;
		text-align: center;
		
		height: 88upx;
		line-height: 88upx;
	}
	.box3{
		flex: 1;
		// height: 100%;
		// border: 1px solid red;
		.name{
			width: 100%;
			height: 118upx;
			// border-bottom: 1px #ebebeb solid;
		}
		text-indent: 36upx;
		.zhengjian{
			width: 100%;
			background-color: red;
			
		}
		.up{
			text-indent: 0;
			border-bottom: none;
			margin-top: 43upx;
			// margin-left: 50upx;
			// text-indent: 0;
			.upx{
				width: 118upx;
				height: 96upx;
			}
		}
		// .ups{
			
		// 	float: left;
		// 	width: 118upx;
		// 	height: 96upx;
		// 	border: dashed #ebebeb 1px;
		// 	position: relative;
		// 	.xian1{
				
		// 		width: 47px;
		// 		height: 1px;
		// 		background-color: #ebebeb;
		// 		position: absolute;
		// 		left: 50%;
		// 		top: 50%;
		// 		transform: translateX(-50%);
		// 	}
		// 	.xian2{
		// 		position: absolute;
		// 		left: 50%;
		// 		top: 50%;
		// 		transform: translateY(-50%);
		// 		height: 47px;
		// 		width: 1px;
		// 		background-color: #ebebeb;
		// 	}
		// }
	}
	
	.mains{
		height: 100%;
		background-color: #ffffff;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin: 0 0;
		text-indent: 0;
		
		border: 1px solid red;
	}
	span{
		color:red
	}
	p{
		font-size: 21upx;
		color:#999999 ;
	}
	h3{
		font-size: 29upx;
	}
	image {
		// background-color: gainsboro;
		border-radius: 50%;
		width: 82upx;
		height: 82upx;
		// border: 1px solid red;
	}
	.headers{
		height: 148upx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		padding-left: 24upx;
		padding-right: 30upx;
		align-items: center;
		.jieshao{
			display: flex;
			.box2{
				margin-left: 20upx;
				// background-color: red;
			}
		}
	}
</style>
